package com.mm.controller;

import com.mm.constant.BusinessConstant;
import com.mm.constant.ResponseConstant;
import com.mm.exception.ServiceException;
import com.mm.model.sys.JsonResponse;
import com.mm.service.ResumeService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 个人简历Controller
 *
 * @date 2018/7/30 11:28
 */
@Controller
@RequestMapping(value = "/resume")
public class ResumeController {
	private static Logger logger = LoggerFactory.getLogger(ResumeController.class);
	@Autowired
	private ResumeService resumeService;
	/**
	 * 保存个人简历
	 */
	@RequestMapping(value = "/save")
	public Object save(HttpServletRequest request){
		Object obj = request.getAttribute(BusinessConstant.PARAMETER_DATA);
		if (obj == null) {
			return new JsonResponse(ResponseConstant.CODE_FAIL, "数据不能为空");
		}
		String data = (String)obj;
		if (StringUtils.isBlank(data)) {
			return new JsonResponse(ResponseConstant.CODE_FAIL, "数据不能为空");
		}
		try {
			resumeService.saveResume(data);
		} catch (ServiceException e) {
			e.printStackTrace();
			logger.error("ResumeController save 保存个人简历: " + e.getMessage());
			return new JsonResponse(ResponseConstant.CODE_FAIL, "保存个人简历失败");
		}
		return "";
	}

}
